package com.lc.luzhengtang.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.luzhengtang.R;
import com.lc.luzhengtang.base.BaseActivity;
import com.lc.luzhengtang.bean.ForgetBean;
import com.lc.luzhengtang.conn.ConnComplant;
import com.lc.luzhengtang.util.LovelyToast;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilMatches;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/3.
 */
public class AppealActivity extends BaseActivity {


    @BindView(R.id.img_news)
    ImageView imgNews;
    @BindView(R.id.text_register)
    TextView textRegister;
    @BindView(R.id.editText_appeal)
    EditText editTextAppeal;
    @BindView(R.id.editText_phone)
    EditText editTextPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appeal);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_news, R.id.text_register, R.id.editText_appeal})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_news:
                finish();
                break;
            case R.id.text_register:
                if (TextUtils.isEmpty(editTextAppeal.getText().toString().trim())) {
                    LovelyToast.makeText(AppealActivity.this, "申诉内容不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (TextUtils.isEmpty(editTextPhone.getText().toString().trim())) {
                    LovelyToast.makeText(AppealActivity.this, "申诉手机号不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (!UtilMatches.checkMobile(editTextPhone.getText().toString())) {
                    LovelyToast.makeText(AppealActivity.this, "请输入正确的手机号", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                    // UtilToast.show(RegisterActivity.this, "请输入正确的手机号");
                } else {

                    getChangePwd();
                }


                break;
            case R.id.editText_appeal:


                break;
        }
    }


    public void getChangePwd() {
        new ConnComplant(editTextPhone.getText().toString().trim(),editTextAppeal.getText().toString().trim(),  new AsyCallBack<ForgetBean>() {
            @Override
            public void onSuccess(String toast, int type, Object o, ForgetBean forgetBean) throws Exception {
                super.onSuccess(toast, type, o, forgetBean);
                if (forgetBean.getCode() == 200) {
                    LovelyToast.makeText(AppealActivity.this, "申诉成功", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else {
                    LovelyToast.makeText(AppealActivity.this, forgetBean.getMessage(), 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                }

                finish();
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
         /*  LovelyToast.makeText(AppealActivity.this, ConnChangePwd.TOAST, 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE); */
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
             /*   LovelyToast.makeText(AppealActivity.this, ConnChangePwd.TOAST, 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);*/
            }
        }

        ).execute(AppealActivity.this, false);
    }

}
